package com.winter.common;

//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;

import java.security.MessageDigest;

/**
 * EncodeUtils工具类
 */
public final class EncodeUtils {

    // private static Logger logger = LoggerFactory.getLogger(EncodeUtils.class);

    /**
     * md5加密
     * 
     * @param source
     * @return
     */
    public static String md5(String source) {
        StringBuffer md5StrBuff = new StringBuffer(32);
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.reset();
            messageDigest.update(source.getBytes("UTF-8"));
            byte[] byteArray = messageDigest.digest();
            for (int i = 0; i < byteArray.length; i++) {
                if (Integer.toHexString(0xFF & byteArray[i]).length() == 1) {
                    md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i]));
                } else {
                    md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
                }
            }
        } catch (Exception e) {
            // logger.error("Can not encode the string " + source + " to MD5!", e);
            return "";
        }
        return md5StrBuff.toString();
    }

    public static void main(String[] args) {
        String md5 = "88f3f6180a20f2604d42fe5b955b8624";
        String md5p = md5("开发商审核中：您的客户胡先生13338004166已经发送至华润置地橡树湾，开发商正在审核中。【房多多】13962172667");
        System.out.println(md5p);
        System.out.println(md5p.equals(md5));
        System.out.println("驻场工作人员已确认您为客户王小姐18662206591带看华润置地橡树湾，开发商接收后您可申请认购，或协助客户转发短信激活带看保护期。【房多多】".length());
    }

}
